package com.openbravo.pos.display.OEM;

import net.xeoh.plugins.base.annotations.PluginImplementation;

import com.openbravo.data.basic.BasicException;
import com.openbravo.format.Formats;
import com.openbravo.pos.config.ParametersConfig;
import com.openbravo.pos.display.OEMDISPLAY_8BIT;
import com.openbravo.pos.printer.PrinterWritterPool;
import com.openbravo.pos.printer.TicketPrinterException;
import com.openbravo.pos.printer.config.ParametersComm;
import com.openbravo.pos.printer.escpos.DeviceDisplaySerial;
import com.openbravo.pos.util.PrinterUtil;

@PluginImplementation
public class ChinaOEMDisplay extends DeviceDisplaySerial{

	public ChinaOEMDisplay() {
	}
	
	@Override
	public void init(String sDisplayParam1, String sDisplayParam2)
			throws TicketPrinterException {
		init(PrinterWritterPool.INSTANCE.getPrinterWritter(sDisplayParam1, sDisplayParam2,2400));
	}

	@Override
	public String getDisplayType() {
		return "ChinaOEM";
	}

	@Override
	public ParametersConfig getConfiguration() {
		return new ParametersComm();
	}

	@Override
	public void repaintLines() {
		
	}

	@Override
	public void writeVisor(int animation, String sLine1, String sLine2) {
		writeVisor(sLine1,sLine2);
	}

	@Override
	public void writeVisor(String sLine1, String sLine2) {
		display.write(OEMDISPLAY_8BIT.VISOR_CLEAR);
		display.write(OEMDISPLAY_8BIT.VISOR_CAN);
		String ledStr=sLine2.trim();
		if(ledStr!=null&&!ledStr.isEmpty())
			if(OEMDISPLAY_8BIT.VISOR_SHOW_PRICE_STR.equalsIgnoreCase(ledStr))
				display.write(OEMDISPLAY_8BIT.VISOR_SHOW_PRICE);
			else if(OEMDISPLAY_8BIT.VISOR_SHOW_TOTAL_STR.equalsIgnoreCase(ledStr))
				display.write(OEMDISPLAY_8BIT.VISOR_SHOW_TOTAL);
			else if(OEMDISPLAY_8BIT.VISOR_SHOW_TAKEING_STR.equalsIgnoreCase(ledStr))
				display.write(OEMDISPLAY_8BIT.VISOR_SHOW_TAKEING);
			else if(OEMDISPLAY_8BIT.VISOR_SHOW_CHANGE_STR.equalsIgnoreCase(ledStr))
				display.write(OEMDISPLAY_8BIT.VISOR_SHOW_CHANGE);
		Double price=null;
		try {
			 price=(Double)Formats.CURRENCY.parseValue(sLine1.trim(), new Double(0));
		} catch (BasicException e) {
			e.printStackTrace();
		}
		display.write(PrinterUtil.alignRight(String.valueOf(price), 8));
		display.flush();
	}

	@Override
	public void initVisor() {
		display.init(OEMDISPLAY_8BIT.INIT);
		display.write(OEMDISPLAY_8BIT.VISOR_CLEAR);
		display.flush();
	}

	@Override
	public void clearVisor() {
		display.write(OEMDISPLAY_8BIT.VISOR_CLEAR);
		display.flush();
	}
	
}
